﻿// --------------------------------
// <copyright file="TableManagerTest.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tronsoft.Actucal.Tables.Test
{
    /// <summary>
    ///This is a test class for TableManagerTest and is intended
    ///to contain all TableManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TableManagerTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        #region Additional test attributes

        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //

        #endregion

        /// <summary>
        ///A test for Instance
        ///</summary>
        [TestMethod()]
        public void InstanceTest()
        {
            TableManager actual;
            actual = TableManager.Instance;
            Assert.AreSame(TableManager.Instance, actual);
        }

        [TestMethod()]
        public void Should_Add_A_Table()
        {
            const string TABLE_NAME = "Table1";

            TableManager.Instance.Clear();
            TableManager.Instance.AddTable(TABLE_NAME);
            TableCollection tables = TableManager.Instance.Tables;

            Assert.AreEqual(1, tables.Count, "Tables should be equal.");
            Assert.IsNotNull(TableManager.Instance.AddTable(TABLE_NAME));
        }

        [TestMethod()]
        public void Should_Add_TableColumn_Definition()
        {
            TableManager tableManager = TableManager.Instance;
            tableManager.Clear();

            tableManager.Tables.Add("table1");
            tableManager.Tables["table1"].Columns.Add("Col1", typeof (int));
            tableManager.Tables["table1"].Columns.Add("Col2", typeof (string));
            tableManager.Tables["table1"].Columns.Add("Col3", typeof (double));
            tableManager.Tables["table1"].Columns.Add("Col4", typeof (string));

            Assert.AreEqual(1, tableManager.Tables.Count);
            Assert.AreEqual(4, tableManager.Tables["table1"].Columns.Count);

            Assert.AreEqual("Col1", tableManager.Tables["table1"].Columns[0].ColumnName);
            Assert.AreEqual("Col2", tableManager.Tables["table1"].Columns[1].ColumnName);
            Assert.AreEqual("Col3", tableManager.Tables["table1"].Columns[2].ColumnName);
            Assert.AreEqual("Col4", tableManager.Tables["table1"].Columns[3].ColumnName);

            Assert.AreEqual(typeof (int), tableManager.Tables["table1"].Columns[0].DataType);
            Assert.AreEqual(typeof (string), tableManager.Tables["table1"].Columns[1].DataType);
            Assert.AreEqual(typeof (double), tableManager.Tables["table1"].Columns[2].DataType);
            Assert.AreEqual(typeof (string), tableManager.Tables["table1"].Columns[3].DataType);
        }

        [TestMethod]
        public void Should_Clear_Tables()
        {
            TableManager tableManager = TableManager.Instance;

            tableManager.Tables.Add("table1");
            tableManager.Clear();

            Assert.AreEqual(0, tableManager.Tables.Count);
        }
    }
}